from django.db import models

from utils.mixins.common_mixins.models import BaseModel


# Create your models here.

class Dictionary(BaseModel):
    dict_name = models.CharField(max_length=255, verbose_name='字典名称', help_text='字典名称')
    dict_key = models.CharField(max_length=255, verbose_name='字典key', unique=True, null=False, blank=False,
                                help_text='字典key')
    dict_type = models.CharField(max_length=255, verbose_name='字典类型', null=False, blank=False, help_text='字典类型',
                                 default='字符串')
    dict_group = models.CharField(max_length=255, verbose_name='字典分组', help_text='字典分组')
    dict_desc = models.CharField(max_length=255, verbose_name='字典描述', help_text='字典描述')

    class Meta:
        db_table = 'dictionaries'
        verbose_name = '字典管理'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.dict_name


class DictionaryDetail(BaseModel):
    dict = models.ForeignKey(Dictionary, on_delete=models.CASCADE, verbose_name='字典', db_constraint=False)
    dict_detail_name = models.CharField(max_length=255, verbose_name='字典详情name', null=False, blank=False,
                                        help_text='字典详情名，用于前端展示')
    dict_detail_key = models.CharField(max_length=255, verbose_name='字典详情key', null=False, blank=False,
                                       help_text='字典详情key，同一字典下key不能重复')
    dict_detail_value = models.CharField(max_length=255, verbose_name='字典详情value', help_text='字典详情值')
    dict_detail_desc = models.CharField(max_length=255, verbose_name='字典详情描述', help_text='字典详情描述')

    class Meta:
        db_table = 'dictionary_details'
        verbose_name = '字典详情管理'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.dict_detail_name
